package com.slz3.business.module.configManagement.conIndexShowImg.service;

import com.slz3.business.frame.enums.ValidFlag;
import com.slz3.business.frame.module.Repositorys;
import com.slz3.business.frame.module.Services;
import com.slz3.business.frame.steward.PageableSteward;
import com.slz3.business.module.configManagement.conIndexShowImg.domain.ConIndexShowImg;
import com.slz3.business.module.configManagement.conIndexShowImg.domain.ConIndexShowImgFactory;
import com.slz3.business.module.configManagement.conIndexShowImg.steward.ConIndexShowImgSpecification;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.domain.Page;
import org.springframework.stereotype.Service;
import org.springframework.util.MultiValueMap;

import java.util.*;

@Slf4j
@Service
public class ConIndexShowImgServiceImpl implements ConIndexShowImgService {

    @Override
    public ConIndexShowImg save(ConIndexShowImg conIndexShowImg) {
        return Repositorys.conIndexShowImg.save(ConIndexShowImgFactory.initBaseFields(conIndexShowImg));
    }

    @Override
    public Page<ConIndexShowImg> page(MultiValueMap<String, String> params) {
        Page<ConIndexShowImg> conIndexShowImgPage = Repositorys.conIndexShowImg.findAll(
                ConIndexShowImgSpecification.findJoin(params), PageableSteward.extract(params)
        );
        return conIndexShowImgPage;
    }

    @Override
    public ConIndexShowImg modify(ConIndexShowImg conIndexShowImgNew) {
        return Repositorys.conIndexShowImg.saveAndFlush(ConIndexShowImgFactory.initBaseFields(conIndexShowImgNew));
    }

    @Override
    public Optional<ConIndexShowImg> single(UUID uuid) {
        return Repositorys.conIndexShowImg.findById(uuid);
    }

    @Override
    public List<ConIndexShowImg> findAllByUuids(Iterable<UUID> uuids) {
        return Repositorys.conIndexShowImg.findAllById(uuids);
    }

    @Override
    public List<ConIndexShowImg> delete(List<ConIndexShowImg> conIndexShowImgList) {
        conIndexShowImgList.stream().forEach(item -> {
            item.setValidFlag(ValidFlag.DEL);
            ConIndexShowImgFactory.initBaseFields(item);
        });
        return Services.conIndexShowImgTransactional.batchModify(conIndexShowImgList);
    }

}
